package gold.digger;

import java.util.*;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC171 {


    /**
     * A -> 1
     * B -> 2
     * C -> 3
     * ...
     * Z -> 26
     * AA -> 27
     * AB -> 28
     *
     * @param s
     * @return
     */

    public static Map<Character, Integer> dict = new TreeMap<>();

    public int titleToNumber(String s) {
        int res = 0;
        for (int i = 0; i < s.length(); i++) {
            res *= 26;
            res += getNum(s.charAt(i));
        }

        return res;
    }

    public static int getNum(char ch) {
        if (dict.containsKey(ch)) {
            return dict.get(ch);
        }

        dict.put(ch, ch - 'A' + 1);
        return dict.get(ch);
    }


    public static void main(String[] args) {
        LC171 an = new LC171();
        String test = "AC";
        System.out.println(an.titleToNumber(test));
    }
}
